home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- Path: in1.uu.net!robcad!usenet
- From: michael@robcad.uucp (Michael Zemmour)
- Subject: Re: division problem
- In-Reply-To: gumboot@airdmhor.gen.nz's message of 30 Jan 1996 05:14:50 +1300
- Message-ID: <MICHAEL.96Jan31131024@saturn.robcad.uucp>
- Sender: usenet@robcad.uucp (Pseudo usenet user for nntp)
- Organization: ROBCAD Ltd. Herzelia - Israel
- References: <31097D77.11AA@rain.org> <4eirpq$8ut@airdmhor.gen.nz>
- Date: Wed, 31 Jan 1996 11:10:24 GMT
-
- In article <4eirpq$8ut@airdmhor.gen.nz> gumboot@airdmhor.gen.nz (Simon Hosie) writes:
-
- > From: gumboot@airdmhor.gen.nz (Simon Hosie)
- > Newsgroups: comp.lang.c
- > Date: 30 Jan 1996 05:14:50 +1300
- > Organization: Airdmhor
- >
- > tpaul:
- > > Can anyone show me why this does not work? I am a beginner.
- >
- > 1> #include <stdio.h>
- >
- > 3> main ()
- > 4> {
- > 5> int fahrenheit, celsius;
- >
- > 7> printf("Fahrenheit temperature =?";
- > 8> scanf("%d",fahrenheit);
- > 9> celsius = 5/9*(fahrenheit-32);
- > 10> printf("Fahrenheit = %d, Celsius = %d", fahrenheit, celsius;
- > 11> }
- >
-
-
-
- #include <stdio.h>
-
- main()
- {
- int fahrenheit, celsius;
- printf("Fahrenheit temperature = ?");
- scanf("%d", &fahrenheit);
- celsius = (int) (5.0/9.0*(fahrenheit-32));
- printf("Fahrenheit = %d, Celsius = %d\n", fahrenheit, celsius);
- }
-
-
- Three things I noticed :
- 1) scanf function accepts as argument only adress of variable.
- In your case, the adresse of your integer variable.
-
- 2) celsius = (int) ...
- The "celsius" variable is an integer and the computation
- you make give you a float. You have to do what is called
- a "casting", that means here to translate the float value
- to an integer value and to set it to your integer variable
- "celsius"
-
- 3) (5/9 ...) This returns you the 0 value. I will be glad to
- understand why. Anyway, you may write instead
- (5.0/9.0 ....)
-
- Hope it helps .
-
- ==============================================================================
- Michael Zemmour
- ROBCAD/Man
- R&D Department
-
- Tecnomatix Technologies Ltd Tel: 972-9-594714
- Delta House 972-9-594777
- 16 Hagalim Avenue Fax: 972-9-544402
- Herzliya 46733 Internet: michael%robcad@uunet.uu.net
- Israel UUCP: uunet!robcad!michael
- ==============================================================================
-
- --
-
-
- >@)
- Michael (V(_
- ===========^^\< ==
-
-
-